package com.firebird.app.kotlin.stock.trend.view

import java.util.List;

import com.firebird.app.kotlin.stock.trend.bean.FsCoordinateSystem
import com.firebird.app.kotlin.stock.trend.bean.Stock

import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.util.AttributeSet
import android.view.View
import android.view.ViewTreeObserver
import android.view.ViewTreeObserver.OnGlobalLayoutListener

/**
 * 绘制分时走势线的视图
 * @author ljk
 * @date   2019年11月4日
 */
class StockFSView : View{
	private var stockList:List<Stock>?=null
	private var paint:Paint?=null
	private var  fsCoordinateSystem:FsCoordinateSystem?=null
	private var  viewWidth:Int=0
    private var viewHeight:Int=0

    constructor(context: Context?) : super(context, null) {}
    constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) {
		//获取视图的尺寸
		val  vto:ViewTreeObserver = this.viewTreeObserver
		vto.addOnGlobalLayoutListener( OnGlobalLayoutListener() {
			 fun onGlobalLayout() {
				//监听器注册后每次视图尺寸发生变化时都会调用，如果只想获取一次视图的尺寸，则需要在获取到视图尺寸后注销掉该监听器
				viewTreeObserver.removeGlobalOnLayoutListener(){}
				viewWidth = width
				viewHeight = height
				fsCoordinateSystem = FsCoordinateSystem(viewWidth,viewHeight)
			}
		})
		paint =  Paint()
	}

	override fun onDraw( canvas:Canvas) {

		if(fsCoordinateSystem != null){
			fsCoordinateSystem!!.drawCoordinateSystem(canvas,paint!!)
		}

	}


	fun setStockList(stockList:List<Stock> ) {
		this.stockList = stockList
	}

}
